
Partial Class Budget_History
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, _
                            ByVal e As System.EventArgs) _
                            Handles Me.Load

        SetupJavaScript()
        EntityController.SetSubNavTabsFinancial(Me.EditCaseSubNav2)
        EntityController.SetFinancialTab(FinancialSubName, EditCaseSubNav2)

        If Not Page.IsPostBack Then
            UserAuthorization.CheckPagePermission(Cdm.DataCore.UserSecurity.Permission.PermissionType.CaseMonthlyStatement, "VIEW")
            UserAuthorization.CheckPagePermission(Cdm.DataCore.UserSecurity.Permission.PermissionType.CaseSpendingPlan, "VIEW")
            Me.BindGrid()
        End If

    End Sub

    Private Sub SetupJavaScript()
        EntityController.JavaScriptAddChildDiv(Me.mainDiv.ClientID, 70)
    End Sub

    Protected Sub BindGrid()

        Me.FinancialHistoryGridView.DataSource = Cdm.DataCore.Budget.FinancialHistory.ListByParticipant(EntityController.GetParticipant.ParticipantId)
        Me.FinancialHistoryGridView.DataBind()

    End Sub

    Protected Sub EditCaseSubNav2_ChangeMenu(ByVal sender As Object, _
                                             ByVal e As System.EventArgs) _
                                             Handles EditCaseSubNav2.ChangeMenu

        EntityController.ReturnToCasePersonalPage(EditCaseSubNav2)

    End Sub

    Protected Sub FinancialHistoryGridView_RowCommand(ByVal sender As Object, _
                                                      ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) _
                                                      Handles FinancialHistoryGridView.RowCommand

        Select Case e.CommandName

            Case "GoSpendingPlan"

                Session("SpendingPlanId") = e.CommandArgument
                Response.Redirect("SpendingPlanView.aspx?id=" + e.CommandArgument)

            Case "GoExpenditureReport"

                Session("ExpenditureReportId") = e.CommandArgument
                Response.Redirect("ExpenditureReportView.aspx?id=" + e.CommandArgument)

        End Select

    End Sub

    Protected Sub FinancialHistoryGridView_RowDataBound(ByVal sender As Object, _
                                                        ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) _
                                                        Handles FinancialHistoryGridView.RowDataBound

        Dim redirectLinkButton As LinkButton
        If e.Row.RowType = DataControlRowType.DataRow Then

            'e.Row.Cells(0).Text = CDate(e.Row.Cells(0).Text).ToString("y")
            'e.Row.Cells(1).Text = FormatCurrency(e.Row.Cells(1).Text, 2)

            redirectLinkButton = CType(e.Row.Cells(2).FindControl("SpendingPlanLinkButton"), LinkButton)
            If redirectLinkButton IsNot Nothing Then
                redirectLinkButton.Text = FormatCurrency(redirectLinkButton.Text, 2)
            End If
            redirectLinkButton = Nothing

            redirectLinkButton = CType(e.Row.Cells(3).FindControl("PaymentsLinkButton"), LinkButton)
            If redirectLinkButton IsNot Nothing Then
                redirectLinkButton.Text = FormatCurrency(redirectLinkButton.Text, 2)
            End If
            redirectLinkButton = Nothing

        End If

    End Sub

End Class
